<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0);
 
%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta HTTP-EQUIV="pragma" CONTENT="no-cache">

<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">

<meta HTTP-EQUIV="expires" CONTENT="0">
		
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />

		<!--[if gt IE 8]>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />        
    <![endif]-->

		<title>添加${sing.title }_${prop.alias }报名属性值</title>

		<%@include file="res.jsp"%>
		<script type="text/javascript">
     	
	     		 function addTr()
	     		 {
		     		var lengthTr = 0 ;  
					//得到所有的行数
					lengthTr = $(".new").length+1 ; 
					
					var rowTemplate = "<tr class='new'><td></td><td><input type='text' name='values' class='validate[required]'></td> <td> <button class='btn btn-danger' onclick='delTr(this);' type='button'>删除</button></td></tr>"
					$(".new").last().after(rowTemplate); 
					ids() ; 
			    }

	     		//删除行
				function delTr(btn)
				{  
					lengthTr = $(".new").length ;   
					if(lengthTr == 1)
					{
						return ; 
					}
					//得到Tr
					var oParent = btn.parentNode.parentNode; 
				
                    document.getElementById('addValueTable').deleteRow(oParent.rowIndex) ; 
 
                    ids() ; 
				}

				function ids()
				{
					//维护id的值 
					$(".new").each(function (key, value) { 
						$(this).children().first().html(key+1) ; 
					});
				}

				function delValue(btn,pId,value)
				{
					//得到Tr
					var oParent = btn.parentNode.parentNode.parentNode;  
					//oParent.remove() ;  
                    
                    document.getElementById('showValueTable').deleteRow(oParent.rowIndex) ;
					  //Post传值删除 
					  var path = "<%=basePath %>page/value_delete.action?time="+(new Date().valueOf()) ;
					  $.post(path,
					  {
						propId:pId,
						val:value
					  },
					  function(data,status){
					    if(status == 'error'){
							alert("删除失败") ; 
						}
					  });
					
					//维护id的值 
					$(".valindex").each(function (key, value) { 
						$(this).children().first().html(key+1) ;  
					});
				}
 
	     </script>

	</head>
	<body>

		<jsp:include page="header.jsp"></jsp:include>

		<jsp:include page="menu.jsp"></jsp:include>

		<jsp:include page="com_bbs.jsp"></jsp:include>
		
		<div class="content">

			<div class="row-fluid">

				<div class="span7">

					<div class="widget">
						<form action="page/value_add.action" method="post" id="validate">
							<div class="head dark">
								<div class="icon">
									<span class="icos-box-add"></span>
								</div>
								<h2>
									添加【${sing.title }_${prop.alias }】报名属性值
								</h2>
							</div>

							<div id="properties_ajax" class="block-fluid">
								<input type="hidden" name="propId" value="${prop.id}">
								<table cellpadding="0" id="addValueTable" cellspacing="0"
									class="table-hover mailbox">
									<thead>
										<tr>
											<th>
												<div class="checker">
													<div class="checker">
														<span><input type="checkbox" class="checkall">
														</span>
													</div>
												</div>
											</th>
											<th width="80%">
												属性值
											</th>
											<th width="20%">
												操作
											</th>
										</tr>
									</thead>
									<tbody>
										<tr class="new">
											<td>
												1
											</td>
											<td>
												<input type="text" name="values" class="validate[required]">
											</td>
											<td>
												<button class="btn btn-danger" onclick="delTr(this);"
													type="button">
													删除
												</button>
											</td>
										</tr>
									</tbody>
								</table>
							</div>
							<div class="toolbar bottom TAL">
								<button class="btn btn-info" type="button" onclick="addTr();">
									添加项
								</button>
								
								<div class="btn-group">
	                                <button onclick="$('#validate').validationEngine('hide');" type="button" class="btn btn-info">隐藏</button>
	                                <button type="submit" class="btn btn-primary">添加</button>
	                            </div> 
							</div>
						</form>
					</div>

				</div>

				<div class="span5">
					<div class="widget">
						<div class="head">
							<div class="icon">
								<i class="icosg-star3"></i>
							</div>
							<h2>
								值列表 
							</h2>
						</div>
						<div class="block-fluid" id="value_block_fluid" >

							<table cellspacing="0" id="showValueTable" cellpadding="0" style="width: 100%"
								class="table-hover mailbox"> 
								<tbody> 
									<c:forEach items="${prop.xmlValue}" var="value" varStatus="state">
										<tr class="valindex">
											<td width="10%">
												${state.index+1 } 
											</td>
											<td width="70%">
												<a class="name" href="#">${value }</a>
											</td>
											
											<td class="TAC" width="20%">  
												<div class="span6">
		                                        	<a onclick="delValue(this,'${prop.id}','${value }')" ><span class="icon-trash"></span></a>
		                                        </div> 
		                                    </td>
										</tr> 
									</c:forEach>
								</tbody>
							</table>
						</div>
						<div class="toolbar bottom">  
						</div>
					</div>
				</div>

			</div>

		</div>
		<div id="value_ajax">

		</div> 
	</body>
</html>

